<template>
	<scroll-view scroll-y :style="{height: height}">
		<lj-layout>
			<view style="padding: 60rpx 30rpx;display: flex;flex-direction: column;gap: 30rpx;">
				<view class="home-box" v-for="(item, index) in moduleList" :key="index" @click="onClickGoModule(item)">
					<view class="label-box">
						<image class="b-icon"
							:src="index % 2 === 0 ? '/pages_nbst/static/images/home/ellipse1.png': '/pages_nbst/static/images/home/ellipse2.png'"
							mode="widthFix" />
						<image class="icon" :src="item.icon" mode="widthFix" />
						<span class="label">{{item.label}}</span>
					</view>
					<image class="tip-icon" src="/pages_nbst/static/images/home/tips-icon.png" mode="widthFix" />
				</view>
			</view>
			<view style="display: flex;justify-content: center;">
				<image src="/pages_nbst/static/images/logoyg.png" mode="widthFix" style="width: 300rpx;height: auto;">
				</image>
			</view>
		</lj-layout>
	</scroll-view>
</template>

<script setup>
	import {
		onLoad
	} from "@dcloudio/uni-app"
	import {
		ref
	} from "vue";
	import LjLayout from "@/pages_nbst/components/lj-layout.vue"
	import tools from "@/pages_nbst/utils/tools.js"
	import {
		updateUserFrom
	} from "@/pages_nbst/api/auth.js"
	import {
		useUserStore
	} from '@/pages_nbst/store/user.js'

	const user = useUserStore()

	const props = defineProps({
		height: String
	})

	const title = '首页'
	const _onShow = (props) => {
		uni.setNavigationBarTitle({
			title: '易公习题册'
		})
		uni.setNavigationBarColor({
			frontColor: '#ffffff',
			backgroundColor: '#6e94c1',
		})
		console.log(title + "_onShow...................", props);
	}

	onLoad((query) => {
		console.log(title + 'onLoad', query);
		tools.login().then(res => {
			user.setUser().then(res => {
				if (query?.from && !user.from) {
					updateUserFrom(query.from).then(res => {
						user.from = query.from
					})
				}
			})
		})
	})

	const moduleList = ref([{
			label: "进门考入口",
			icon: "/pages_nbst/static/images/home/home-icon-1.png",
			path: '/pages_nbst/views/home/eoexam?type=1'
		},
		{
			label: "出门考入口",
			icon: "/pages_nbst/static/images/home/home-icon-2.png",
			path: '/pages_nbst/views/home/eoexam?type=0'
		},
		// {
		// 	label: "周考入口",
		// 	icon: "/pages_nbst/static/images/home/home-icon-3.png",
		// 	path: '/pages_nbst/views/home/weekexam'
		// },
		// {
		// 	label: "月考入口",
		// 	icon: "/pages_nbst/static/images/home/home-icon-4.png",
		// 	path: '/pages_nbst/views/home/monthexam'
		// },
		// {
		// 	label: "刷题入口",
		// 	icon: "/pages_nbst/static/images/home/home-icon-5.png",
		// 	path: '/pages_nbst/views/home/exercise'
		// },
	])

	const onClickGoModule = (item) => {
		uni.navigateTo({
			url: item.path
		})
	}

	defineExpose({
		_onShow
	});
</script>

<style scoped lang="scss">
	.home-box {
		display: flex;
		justify-content: space-between;
		align-items: center;
		border-radius: 10rpx;
		background-color: white;
		box-shadow: 0 0 20rpx rgba(0, 0, 0, 0.1);

		.label-box {
			padding: 20rpx 0;
			display: flex;
			align-items: center;
			gap: 50rpx;

			.b-icon {
				width: 16rpx;
				height: auto;
			}

			.icon {
				width: 76rpx;
				height: auto;
			}

			.label {
				font-size: 40rpx;
				color: #484848;
			}
		}

		.tip-icon {
			width: 30rpx;
			height: auto;
			margin-right: 60rpx;
		}
	}
</style>